
<template>
  <div class="login">
    <div class="login-form">
      <div class="logo-img">
        <img src="../../assets/images/icons/brand.png"
             height="42px" />
        <div class="title">蝌蚪智慧银行学习云平台</div>
      </div>
      <div class="sub-title">用户登录</div>
      <div class="input-item">
        <div class="input-item-container">
          <div><img src="../../assets/images/icons/user.png"
                 height="30px" /></div>
          <div><input type="text"
                   v-model="username"
                   placeholder="请输入登录账号" /></div>
        </div>
      </div>
      <div class="input-item">
        <div class="input-item-container">
          <div><img src="../../assets/images/icons/password.png"
                 height="30px" /></div>
          <div><input type="password"
                   v-model="password"
                   placeholder="请输入密码" /></div>
        </div>
      </div>
      <div class="input-item">
        <div class="input-item-container">
          <div><img src="../../assets/images/icons/code.png"
                 height="30px" /></div>
          <div><input type="text"
                   v-model="strImageVerifyCode"
                   @keyup.enter="loginUser"
                   placeholder="请输入验证码" /></div>
          <div class="verfiy-img">
            <img height="35px"
                 width="80px"
                 @click="updateImageVerifyCode"
                 :src="`data:image/jpg;base64,${imageVerifyCode}`" />
          </div>
        </div>
      </div>
      <div>
        <div class="login-button"
             @click="loginUser">登录</div>
      </div>
    </div>
  </div>
</template>

<script>
  import { mapGetters, mapActions, mapMutations } from "vuex";
  import consts from "@/const";
  const { user } = consts;

  export default {
    name: "login",
    data() {
      return {
        title: "login",
        strImageVerifyCode: "",
        username: "",
        password: "",
        rememberMe: false
      };
    },
    mounted() {
      this.getImageVerifyCode();
    },
    computed: {
      ...mapGetters(["imageVerifyCode"])
    },
    methods: {
      ...mapActions(["getImageVerifyCode", "checkImageVerifyCode", "formLogin"]),
      updateImageVerifyCode() {
        this.getImageVerifyCode();
      },
      loginUser() {
        this.checkImageVerifyCode({
          code: this.strImageVerifyCode,
          success: () => {
            this.formLogin({
              data: {
                username: this.username,
                password: this.password,
                rememberMe: this.rememberMe
              },
              success: userInfo => {
                console.log("LOGIN OK", userInfo);
                if (userInfo.userType === user.BANK_TRAINEE) {
                  this.$router.push({
                    name: "traineeHome"
                  });
                } else {
                  this.$router.push({
                    name: "home"
                  });
                }
              }
            });
          }
        });
      }
    }
  };
</script>

<style lang="less">
.login {
  display: table;
  width: 100%;
  height: 100%;
  min-width: 1024px;
  min-height: 600px;
  font-size: 20px;
  color: #606266;
  background-image: url(../../assets/images/loginbg.png);
  background-repeat: no-repeat;
  background-size: 100% 100%;
  .login-form {
    width: 280px;
    padding-left: calc(20% - 180px);
    display: table-cell;
    vertical-align: middle;
  }
  .verfiy-img {
    position: absolute;
    right: 25px;
    cursor: pointer;
    padding-bottom: 2px;
  }
  .logo-img {
    display: flex;
    padding-bottom: 8px;
  }
  .title {
    font-size: 28px;
    color: var(--global-color);
    padding-top: 6px;
    padding-left: 10px;
  }
  .sub-title {
    font-size: 22px;
    padding-bottom: 8px;
  }
  .input-item {
    display: flex;
    padding: 15px 0px 0px 0px;
  }
  .input-item-container {
    display: inline-flex;
    background-color: #fcf0e9;
    border-radius: 50px;
    padding: 10px 15px 5px 18px;
    position: relative;
  }
  .remember-item-container {
    display: inline-flex;
    padding: 5px 15px 5px 15px;
    font-size: 18px;
    .remember-me {
      padding-left: 10px;
      cursor: pointer;
    }
  }
  .login-button {
    cursor: pointer;
    display: inline-block;
    border-radius: 50px;
    font-size: 22px;
    padding: 13px 125px;
    margin-top: 15px;
    background-color: var(--global-color);
    color: white;
    -webkit-box-shadow: 0 3px 10px rgba(242, 101, 34, 0.5);
    box-shadow: 0 3px 10px rgba(242, 101, 34, 0.5);
  }
  .login-button:hover {
    -webkit-box-shadow: 0 6px 10px rgba(242, 101, 34, 0.5);
    -moz-box-shadow: 0 6px 10px rgba(242, 101, 34, 0.5);
    box-shadow: 0 6px 10px rgba(242, 101, 34, 0.5);
  }
  input {
    border-width: 0px;
    border: none;
    background: none;
    font-size: 22px;
    height: 30px;
    padding-left: 10px;
    color: #606266 !important;
  }
  input:focus {
    outline: none;
  }
  input:-webkit-autofill,
  input:-webkit-autofill:hover,
  input:-webkit-autofill:focus,
  input:-webkit-autofill:active {
    transition: background-color 5000s ease-in-out 0s;
  }
}
</style>

